package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ReportSetting;
import com.ruoyi.system.service.IReportSettingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 举报设置Controller
 * 
 * @author DEREK
 * @date 2023-08-10
 */
@RestController
@RequestMapping("/system/reportSetting")
public class ReportSettingController extends BaseController
{
    @Autowired
    private IReportSettingService reportSettingService;

    /**
     * 查询举报设置列表
     */
    @PreAuthorize("@ss.hasPermi('system:reportSetting:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReportSetting reportSetting)
    {
        startPage();
        List<ReportSetting> list = reportSettingService.selectReportSettingList(reportSetting);
        return getDataTable(list);
    }

    /**
     * 导出举报设置列表
     */
    @PreAuthorize("@ss.hasPermi('system:reportSetting:export')")
    @Log(title = "举报设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReportSetting reportSetting)
    {
        List<ReportSetting> list = reportSettingService.selectReportSettingList(reportSetting);
        ExcelUtil<ReportSetting> util = new ExcelUtil<ReportSetting>(ReportSetting.class);
        util.exportExcel(response, list, "举报设置数据");
    }

    /**
     * 获取举报设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:reportSetting:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(reportSettingService.selectReportSettingById(id));
    }

    /**
     * 新增举报设置
     */
    @PreAuthorize("@ss.hasPermi('system:reportSetting:add')")
    @Log(title = "举报设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReportSetting reportSetting)
    {
    	reportSetting.setType(1);
        return toAjax(reportSettingService.insertReportSetting(reportSetting));
    }

    /**
     * 修改举报设置
     */
    @PreAuthorize("@ss.hasPermi('system:reportSetting:edit')")
    @Log(title = "举报设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReportSetting reportSetting)
    {
        return toAjax(reportSettingService.updateReportSetting(reportSetting));
    }

    /**
     * 删除举报设置
     */
    @PreAuthorize("@ss.hasPermi('system:reportSetting:remove')")
    @Log(title = "举报设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(reportSettingService.deleteReportSettingByIds(ids));
    }
}
